/**
 * This file is part of AppStoreBot.
 *
 * AppStoreBot is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * AppStoreBot is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with AppStoreBot.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
package lu.pragmaconsult.appstorebot;

import java.util.HashMap;
import java.util.Map;

import com.sampullara.cli.Argument;

/**
 * 
 * Bot settings. Must serve to configure a Bot and could be utilize as an
 * external API peace to allow usage as a framework.
 * 
 * @author Wilfried Vandenberghe (wilfried.vandenberghe at pragmaconsult.lu)
 */
public class BotContext {

	/**
	 * Display usage message.
	 */
	@Argument(alias = "h", description = "print this help message and exit")
	private boolean help;

	/**
	 * Apple ID.
	 */
	@Argument(value = "appleId", alias = "a", description = "your apple id (required)")
	private String appleId;

	/**
	 * Password (not encrypted)
	 */
	@Argument(value = "password", alias = "p", description = "your password")
	private String password;

	/**
	 * Password from stdin
	 */
	@Argument(value = "passwordStdin", alias = "P", description = "read the password from stdin")
	private boolean passwordStdin;

	/**
	 * Output directory to store report file.
	 */
	@Argument(value = "outputDirectory", alias = "o", description = "directory where download file is stored, default is the current working directory")
	private String outputDiretory;

	/**
	 * Verbose mode.
	 */
	@Argument(alias = "v", description = "verbose output, default is off")
	private boolean verbose;

	/**
	 * Unzip report file.
	 */
	@Argument(alias = "u", description = "unzip download file, default is off")
	private boolean unzip;

	/**
	 * Number of days to download.
	 */
	@Argument(value = "days", alias = "d", description = "number of days to download, default is 1")
	private Integer days = 1;

	/**
	 * Report date to download.
	 */
	@Argument(value = "date", alias = "D", description = "(mm/dd/yyyy) report date to download, -d option is ignored when -D is used")
	private String date;

	/**
	 * Debug enable.
	 */
	@Argument(description = "debug output, default is off")
	private boolean debug;

	/**
	 * Download weekly report.
	 */
	@Argument(value = "weekly", alias = "w", description = "download weekly report")
	private boolean weekly;

	/**
	 * A store for key/value pair.
	 */
	private Map<String, String> context = new HashMap<String, String>();

	/**
	 * Is Bot should display usage message.
	 * 
	 * @return should display usage message
	 */
	public final boolean isHelp() {
		return help;
	}

	/**
	 * Set display usage message flag.
	 * 
	 * @param help
	 *            display usage flag
	 */
	public final void setHelp(boolean help) {
		this.help = help;
	}

	/**
	 * Get Apple ID
	 * 
	 * @return apple ID
	 */
	public final String getAppleId() {
		return appleId;
	}

	/**
	 * Set Apple ID
	 * 
	 * @param appleId
	 *            apple ID
	 */
	public final void setAppleId(String appleId) {
		this.appleId = appleId;
	}

	/**
	 * Get password
	 * 
	 * @return password
	 */
	public final String getPassword() {
		return password;
	}

	/**
	 * Set password
	 * 
	 * @param password
	 *            password to set
	 */
	public final void setPassword(String password) {
		this.password = password;
	}

	/**
	 * ACTUALLY NOT SUPPORTED
	 * 
	 * @return
	 */
	public final boolean isPasswordStdin() {
		return passwordStdin;
	}

	/**
	 * ACTUALLY NOT SUPPORTED
	 * 
	 * @param passwordStdin
	 */
	public final void setPasswordStdin(boolean passwordStdin) {
		this.passwordStdin = passwordStdin;
	}

	/**
	 * Get output directory to store downloaded report. If none is set, report
	 * is downloaded in the current directory.
	 * 
	 * @return output directory
	 */
	public final String getOutputDiretory() {
		return outputDiretory;
	}

	/**
	 * Set output directory to store download report.
	 * 
	 * @param outputDiretory
	 *            an existing directory
	 */
	public final void setOutputDiretory(String outputDiretory) {
		this.outputDiretory = outputDiretory;
	}

	/**
	 * Get verbose
	 * 
	 * @return verbose
	 */
	public final boolean isVerbose() {
		return verbose;
	}

	/**
	 * Set verbose flag
	 * 
	 * @param verbose
	 *            verbose flag
	 */
	public final void setVerbose(boolean verbose) {
		this.verbose = verbose;
	}

	/**
	 * Get unzip flag. If true, report will be stored as unziped file.
	 * 
	 * @return unzip flag
	 */
	public final boolean isUnzip() {
		return unzip;
	}

	/**
	 * Set unzip flag.
	 * 
	 * @param unzip
	 *            unzip flag
	 */
	public final void setUnzip(boolean unzip) {
		this.unzip = unzip;
	}

	/**
	 * Get number of reports to download.
	 * 
	 * @return reports number
	 */
	public final int getDays() {
		return days;
	}

	/**
	 * Set report number to download.
	 * 
	 * @param days
	 *            report number
	 */
	public final void setDays(int days) {
		this.days = days;
	}

	/**
	 * Get report date to download.
	 * 
	 * @return report date
	 */
	public final String getDate() {
		return date;
	}

	/**
	 * Set report date to download.
	 * 
	 * @param date
	 *            report date
	 */
	public final void setDate(String date) {
		this.date = date;
	}

	/**
	 * Is debug enable
	 * 
	 * @return debug enable
	 */
	public final boolean isDebug() {
		return debug;
	}

	/**
	 * Set debug enable
	 * 
	 * @param debug
	 *            enable
	 */
	public final void setDebug(boolean debug) {
		this.debug = debug;
	}

	/**
	 * Get the value corresponding to this attribute
	 * 
	 * @param attribute
	 *            context key to retrieve a value
	 * @return corresponding value
	 */
	public final String getContextAttribute(String attribute) {
		return context.get(attribute);
	}

	/**
	 * Set a key/value pair into the context.
	 * 
	 * @param attribute
	 *            key to set
	 * @param value
	 *            value to set
	 */
	public final void setContextAttribute(String attribute, String value) {
		context.put(attribute, value);
	}

	/**
	 * Download weekly report
	 * 
	 * @return download weekly report
	 */
	public boolean isWeekly() {
		return weekly;
	}

	/**
	 * Set report type to download to weekly
	 * 
	 * @param weekly
	 *            report type
	 */
	public void setWeekly(boolean weekly) {
		this.weekly = weekly;
	}
}
